'use strict';
//////////////////////////////////////////////////////////////////////////////
// 日期范围控件 datepicker1
// =====================
// liuyp 2018年11月28日15: 30: 04
//////////////////////////////////////////////////////////////////////////////
function leDate ($timeout){
    return {
        restrict: "E",
        replace: true,
        scope: { bdate: "=", edate: "=", title: "=" },
        template: "<div></div>",
        link: function($scope, el, $attrs){
            var $element = $(el)
            function init(b,e){
                $element.html("")
                $element.datepicker1([b,e], $scope.title, function (date) {
                    $timeout(function(){
                        if (date.length > 1) { $scope.bdate = date[0]; $scope.edate = date[1]; }
                        else { $scope.bdate = date[0]; $scope.edate = date[0]; }
                    },100)
                },{showFuture: $attrs.showfuture})
            }
            $scope.$watch('bdate', function (newVal) {
                init(newVal, $scope.edate)
            }, true)
            $scope.$watch('edate', function (newVal) {
                init($scope.bdate, newVal)
            }, true)
        }
    }
}
exports = module.exports = leDate;